package com.otv.model;

import java.math.BigDecimal;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.PostLoad;
import javax.persistence.Transient;

import com.otv.ui.RessourceHelper;

@Entity
public class Operation {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinTable(name = "operation_tempsunitaire", joinColumns = { @JoinColumn(name = "operation_id", nullable = true, updatable = true) }, inverseJoinColumns = { @JoinColumn(name = "tempsunitaire_id", nullable = true, updatable = true) })
	private List<TempsUnitaire> tempsUnitaire;
	@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinTable(name = "operation_quantite", joinColumns = { @JoinColumn(name = "operation_id", nullable = true, updatable = true) }, inverseJoinColumns = { @JoinColumn(name = "quantite_id", nullable = true, updatable = true) })
	private List<Quantite> quantities;
	private Boolean magasinCanDeleteOperation;
	private BigDecimal coeffecient;
	@Transient
	private String coeffecientString;
	private Integer number;
	private FormuleDeCalcule formuleDeCalcul;
	@Transient
	private String magasinCanDeleteOperationCirclePath;
	private String name;

	@PostLoad
	public void onPostLoad() {
		if(coeffecient != null)
		{
		String plainString = coeffecient.toPlainString();
		coeffecientString = plainString;
		}
		if (magasinCanDeleteOperation) {
			magasinCanDeleteOperationCirclePath = RessourceHelper.whiteCirclePath;
		} else {
			magasinCanDeleteOperationCirclePath = RessourceHelper.redCirclePath;
		}
	}

	public Integer getNumber() {
		return number;
	}

	public void setNumber(Integer number) {
		this.number = number;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public List<TempsUnitaire> getTempsUnitaire() {
		return tempsUnitaire;
	}

	public void setTempsUnitaire(List<TempsUnitaire> tempsUnitaire) {
		this.tempsUnitaire = tempsUnitaire;
	}

	public List<Quantite> getQuantities() {
		return quantities;
	}

	public void setQuantities(List<Quantite> quantities) {
		this.quantities = quantities;
	}


	public Boolean getMagasinCanDeleteOperation() {
		return magasinCanDeleteOperation;
	}

	public void setMagasinCanDeleteOperation(Boolean magasinCanDeleteOperation) {
		this.magasinCanDeleteOperation = magasinCanDeleteOperation;
	}

	public String getMagasinCanDeleteOperationCirclePath() {
		return magasinCanDeleteOperationCirclePath;
	}

	public void setMagasinCanDeleteOperationCirclePath(
			String magasinCanDeleteOperationCirclePath) {
		this.magasinCanDeleteOperationCirclePath = magasinCanDeleteOperationCirclePath;
	}

	public BigDecimal getCoeffecient() {
		return coeffecient;
	}

	public void setCoeffecient(BigDecimal coeffecient) {
		this.coeffecient = coeffecient;
	}

	public FormuleDeCalcule getFormuleDeCalcul() {
		return formuleDeCalcul;
	}

	public void setFormuleDeCalcul(FormuleDeCalcule formuleDeCalcul) {
		this.formuleDeCalcul = formuleDeCalcul;
	}

	public String getCoeffecientString() {
		return coeffecientString;
	}

	public void setCoeffecientString(String coeffecientString) {
		this.coeffecientString = coeffecientString;
	}

}
